home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
8_5.lha
/
8_5
/
scanset1.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
1KB
|
54 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ construct the scanset
canset::scanset(const char *pattern, const char **retpat)
// Set the value which indicates a match based
// on whether the set is complemented or not.
int match = 1;
if (*pattern == '^')
{
match = 0;
pattern++;
}
// Initialize the array for all non-matches.
memset(set, !match, UCHAR_MAX + 1);
// The first character is special and
// can contain `]' or `-'.
if ((*pattern == ']') || (*pattern == '-'))
set[*pattern++] = match;
// Run down the pattern looking for the `]',
// setting appropriate members of the
// set to match.
for ( ; *pattern && (*pattern != ']'); pattern++)
// either a range or trailing `-'
if (*pattern == '-')
{
// special case for trailing `-'
if (pattern[1] == ']')
set['-'] = match;
// char range, a-z
else
{
for (int i = pattern[-1] + 1;
i <= pattern[1]; i++)
set[i] = match;
pattern++;
}
}
else
set[*pattern] = match;
// The pattern now points to the `]'.
// Return the value just beyond it.
if (retpat)
*retpat = pattern + 1;